<?php
/**
 * Created by PhpStorm.
 * User: Guangpeng Chen
 * Date: 15-2-9
 * Time: 下午3:16
 */
include("/var/www/html/new/com.inc.php");
include("/var/www/html/alipay/alipay.config.php");
include("/var/www/html/alipay/lib/alipay_notify.class.php");
include("/var/www/html/new/d/class/OrderRecord.php");

$ac=$GLOBALS['_ac'];
$pw=$GLOBALS['_pw'];
$s = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));
$out_trade_no = '669180';
$str="select status,royalty_parameters,total_fee from pft_alipay_rec where out_trade_no='$out_trade_no' limit 1";
$GLOBALS['le']->query($str);
$GLOBALS['le']->fetch_assoc();
$status=$GLOBALS['le']->f('status');
$royalty_parameters=$GLOBALS['le']->f('royalty_parameters');
$total_fee=$GLOBALS['le']->f("total_fee") * 100;


    $ordern = $out_trade_no;

    $or=new OrderRecord($ordern,$s);
    $orders=$or->info();

//    total_fee($orders);

    $aid = (string)$orders['mainOrder']->UUaid;
    $mid = (string)$orders['mainOrder']->UUmid;
//    fenRun($s,$ordern,$total_fee,$orders,true);

//    $s->reSend_SMS_Global_PL($ordern,$aid,$mid);//最后重发短信
//    $s->Mod_Order_Status($ordern,1,1);
    //更新远端订单号
//    $updateRemote = $s->Remote_Ordernum_Update(serialize(array($ordern=>'PC_ALIPAY_PFT_'.$_SERVER['REQUEST_TIME'])));
//            write_logs("RemoteOrdernumUpdate|RES={$updateRemote}|[$ordern]");
    //发送微信通知
    define('DEFAULT_WECHAT_APPID', 'wxd72be21f7455640d');//票付通公众号
    //TODO::包含全局文件
    include '/var/www/html/wx/wechat/iwx.php';

//    if ($_SERVER['REQUEST_TIME']<strtotime('2015-02-17 00:00:00')) {
//        $wx_open_id = 'oNbmEuGRtiN4dpSUa4EnKtijHuQc';//通知财务-陈琼容
//    } else {
//        $wx_open_id = 'oNbmEuCJxEEnEbfrsdYhbDKxp9LY';//通知财务-宋姐
//    }
    $wx_open_id = 'oNbmEuCJxEEnEbfrsdYhbDKxp9LY';//通知财务-宋姐

    //TODO::微信发送通知
    $data        = array(
        'first'     => array('value'=>'不妙，有客户申请退款啦！','color'=>'#173177'),
        'reason'    => array('value'=>'取消订单退款','color'=>'#173177'),
        'refund'    => array('value'=> 123 . 'RMB','color'=>'#ff9900'),
        'remark'    => array('value'=> "订单号：123333",'color'=>''),
    );

    $msgRet = \LaneWeChat\Core\TemplateMessage::sendTemplateMessage($data,
        $wx_open_id, 'vssudy2AGBlkZpygUbxlMAnLyOYYmtYvXfn0QvfoFRs',
        "http://wx.12301.cc/html/order_detail.html?fromt=f542e9fac6e76f4b3b66422d49e5585c&ordernum={$ordern}",
        '#FF0000');
    exit;
    //STEP TWO->获取openid
    $sqlWx = "SELECT fromusername FROM uu_wx_member_pft WHERE fid=$mid AND tousername='".DEFAULT_WECHAT_APPID."' LIMIT 1";
    $stmt = \LaneWeChat\Core\Db::Connect()->prepare($sqlWx);
    $stmt->execute();
    $wx_open_id = $stmt->fetchColumn(0);
    echo("sqlWx=$sqlWx" );
    if ($wx_open_id) {
        echo("wx_open_id=$wx_open_id");

        $data        = array(
            'first'=> array('value'=>'订单提交成功','color'=>'#173177'),
            'tradeDateTime'=> array('value'=>(string)$orders['mainOrder']->UUordertime,'color'=>'#173177'),
            'orderType'=> array('value'=> '门票预定','color'=>'#ff9900'),
            'customerInfo'=> array('value'=> (string)$orders['mainOrder']->UUordername,'color'=>'#173177'),
            'orderItemName'=> array('value'=> (string)$orders['mainOrder']->UUltitle,'color'=>'#173177'),
            'orderItemData'=> array('value'=> (string)$orders['mainOrder']->UUttitle . (int)$orders['mainOrder']->UUtnum .'张','color'=>'#173177'),
            'remark'       => array('value'=> "订单号：{$ordern}",'color'=>''),
        );
        echo("wx_open_id=$wx_open_id");
        $msgRet = \LaneWeChat\Core\TemplateMessage::sendTemplateMessage($data,
            $wx_open_id, '5QVNlRb5D9Fw3mFGIF5fhonoH42FPAbwllu5Au2013c',
            "http://wx.12301.cc/html/order_detail.html?fromt=f542e9fac6e76f4b3b66422d49e5585c&ordernum={$ordern}",
            '#FF0000');
        echo("TemplateMessage|RES=" .json_encode($msgRet));
    }
